package net.zjitc.servlet.product;

import net.zjitc.domain.Product;
import net.zjitc.service.ProductService;
import net.zjitc.service.impl.ProductServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 2 * @Author: 洪瑶
 * 3 * @Date: 2018/11/1 16:08
 * 4
 */
@WebServlet(name = "AppendServlet",urlPatterns = "/append")
public class AppendServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Product p = new Product();
        try {
            BeanUtils.populate(p,request.getParameterMap());
            ProductService service =new ProductServiceImpl();
            Boolean count = service.Add(p);
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.sendRedirect(getServletContext().getContextPath()+"/findPage");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
